//
//  DiagnoseHappinessViewController.swift
//  Psychologist
//
//  Created by sdw on 15/11/28.
//  Copyright (c) 2015年 ai.com. All rights reserved.
//

import UIKit

class DiagnoseHappinessViewController : HappinessViewController,UIPopoverPresentationControllerDelegate{
    override var happiness: Int{
        didSet{
            diagnosticHistory += [happiness]
        }
    }
    
    private let defaults = NSUserDefaults.standardUserDefaults()
    
    var diagnosticHistory :[Int]{
        get { return defaults.objectForKey(History.DefaultsKey) as? [Int] ?? [] }
        set { defaults.setObject(newValue, forKey: History.DefaultsKey)}
        
    }
    
    
    private struct History{
        static let SegueIdentifier = "showHistory"
        static let DefaultsKey = "DiagnoseHappinessViewController.History"
    }
    
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if let identifier = segue.identifier{
            switch identifier {
            case History.SegueIdentifier :
                if let hvc = segue.destinationViewController as? HistoryViewController{
                    if let ppc = hvc.popoverPresentationController{
                        ppc.delegate = self
                    }
                    hvc.text = "\(diagnosticHistory)"
                }
            default: break
            }
        }
        
    }
    func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
        return UIModalPresentationStyle.None
    }
    
    
}